package com.chinaoly.baotou.common.page;



import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("分页查询: P")
public class P<T> {

    @ApiModelProperty("当前页数据")
    private List<T> records;

    @ApiModelProperty("总条数")
    private long total;

    @ApiModelProperty("每页条数")
    private long size;

    @ApiModelProperty("第几页")
    private long current;

    @ApiModelProperty("sortCursor 游标")
    private Object[] sortCursor;

    public P(List<T> records, long total, long size, long current) {
        this.records = records;
        this.total   = total;
        this.size    = size;
        this.current = current;
    }

    public P(List<T> records, Page page) {
        this.records = records;
        this.total   = page.getTotal();
        this.size    = page.getSize();
        this.current = page.getCurrent();
    }

    public static P of(List records, Page page) {
        return new P(records, page);
    }

    public static <T> P<T> of(Page<T> page) {
        return new P<>(page.getRecords(), page);
    }
}
